package com.jk.vehicle.mini.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.jk.vehicle.mini.dao.OrderMapper;
import com.jk.vehicle.mini.entity.Order;
import com.jk.vehicle.mini.service.OrderService;
import com.jk.vehicle.mini.vo.NetAndProdDetailsVo;
import com.jk.vehicle.core.service.impl.AbstractService;
import com.jk.vehicle.mini.util.QueryUtil;
import com.jk.vehicle.mini.util.SequenceUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.EntityColumn;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.mapperhelper.EntityHelper;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Date;

/**
 * This is Description for OrderServiceImpl
 *
 * @author Administrator
 * @date 2021/06/18
 */
@Service
public class OrderServiceImpl extends AbstractService<Order> implements OrderService {
    /**
	 * 注入OrderMapper
	 */
    @Resource
    private OrderMapper bizOrderMapper;

    /**
    * 根据查询条件查询单表数据
    * @param paramMap 查询条件
    * @return 查询结果
    */
    public List<Order> queryByParams(Map<String, Object> paramMap){
        Condition condition = new Condition(Order.class);
        Example.Criteria criteria = condition.createCriteria();
        Map<String, EntityColumn> propertyMap = EntityHelper.getEntityTable(Order.class).getPropertyMap();
        QueryUtil.spliceQueryParam(criteria, paramMap,  propertyMap, condition);
        return bizOrderMapper.selectByCondition(condition);
    }

    /**
     * 根据车辆序列号网点和商品详情
     * @param bicycleId
     * @return
     */
    @Override
    @DS("#last")
    public NetAndProdDetailsVo selectNetAndProdDetailsById(Long bicycleId, String dsName) {
        return bizOrderMapper.selectNetAndProdDetailsById(bicycleId);
    }

    @Override
    @DS("#last")
    public void save(Order bizOrder, String dsName) {
        bizOrder.setId(SequenceUtils.nextId());
        bizOrder.setCreateDate(new Date());
        super.save(bizOrder, dsName);
    }

    @Override
    @DS("#last")
    public void update(Order bizOrder, String dsName){
        bizOrder.setUpdateDate(new Date());
        super.update(bizOrder, dsName);
    }
}
